package com.zucc.controller;

import com.zucc.controller.req.CategoryAddReq;
import com.zucc.controller.req.CategoryModifyReq;
import com.zucc.controller.req.CategorySearchReq;
import com.zucc.controller.resp.CategoryResp;
import com.zucc.service.CategoryService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : charspan
 * @Description :
 * @create : 2021-12-11 8:51 下午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/categories")
@Api(tags = "资源分类管理")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @ApiOperation(value = "新增资源分类")
    @PostMapping
    void add(@RequestBody @Validated CategoryAddReq req) {
        categoryService.add(req);
    }

    @ApiOperation(value = "修改资源分类")
    @PutMapping
    void modify(@RequestBody @Validated CategoryModifyReq req) {
        categoryService.modify(req);
    }

    @ApiOperation(value = "删除资源分类")
    @ApiImplicitParam(paramType = "path", name = "id", value = "资源分类编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    void deleteOne(@PathVariable Long id) {
        categoryService.deleteOne(id);
    }

    @ApiOperation(value = "资源分类分页")
    @PostMapping("/page")
    PageData<CategoryResp> page(@RequestBody @Validated CategorySearchReq req) {
        return categoryService.page(req);
    }
}
